package com.project.base.common;

import java.io.*;

/*
 * 序列化工具
 */
public class SerializeUtil {

    /*
     * 序列化
     */
    public static byte[] serialize(Object obj) {
        ByteArrayOutputStream bop = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oop = new ObjectOutputStream(bop);
            oop.writeObject(obj);
            byte[] objByte = bop.toByteArray();
            return objByte;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /*
     * 反序列化
     */
    public static Object deSerialize(byte[] byteArray) {
        ByteArrayInputStream bip = new ByteArrayInputStream(byteArray);
        try {
            ObjectInputStream oip = new ObjectInputStream(bip);
            Object obj = oip.readObject();
            return obj;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}
